<template>
  <div class="login-container">
    <div class="login-box">
      <h1 class="login-title">欢迎登录</h1>
      <el-form @submit.prevent="handleLogin" class="login-form">
        <div class="form-group">
          <label>用户名</label>
          <!-- 使用对象绑定方式引用图标 -->
          <el-input 
            v-model="username" 
            placeholder="请输入用户名" 
            :prefix-icon="EditPen" 
          />
        </div>
        <div class="form-group">
          <label>密码</label>
          <el-input 
            v-model="password" 
            type="password" 
            show-password 
            placeholder="请输入密码" 
            :prefix-icon="EditPen" 
          />
        </div>
        <el-button native-type="submit" class="login-button">登录</el-button>
        <p v-if="errorMessage" class="error-message">{{ errorMessage }}</p>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
// 按需导入EditPen图标
import { EditPen } from '@element-plus/icons-vue'

const username = ref('')
const password = ref('')
const errorMessage = ref('')
const router = useRouter()

const handleLogin = () => {
  if (username.value === 'admin' && password.value === '123456') {
    localStorage.setItem('isAuthenticated', 'true')
    router.push({ name: 'home' })
  } else {
    errorMessage.value = '用户名或密码错误'
  }
}
</script>

<style scoped>
/* 保持原有样式不变 */
</style>    

<style scoped>
.login-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #f5d0fe 0%, #c4b5fd 100%);
  padding: 2rem;
}


.login-box {
  background: white;
  padding: 2.5rem;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 400px;
}

.login-title {
  color: #8b5cf6;
  text-align: center;
  margin-bottom: 2rem;
  font-size: 1.8rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-group label {
  color: #6d28d9;
  font-weight: 500;
}

.form-group input {
  padding: 0.8rem;
  border: 2px solid #e9d5ff;
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.3s;
}

.form-group input:focus {
  outline: none;
  border-color: #8b5cf6;
}

.login-button {
  background-color: #8b5cf6;
  color: white;
  border: none;
  padding: 0.8rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.3s;
  margin-top: 1rem;
}

.login-button:hover {
  background-color: #7c3aed;
}

.error-message {
  color: #ef4444;
  text-align: center;
  margin-top: 1rem;
}
</style>  